﻿Imports Entities
Public Class ChoferDAL
    Public Shared Function List() As List(Of CHOFERES)
        Using bd As New gas_gasdesuvecinoEntities
            Dim query = From rec In bd.CHOFERES
                       Where rec.ACTIVO
                         Order By rec.APELLIDOPATERNO Ascending
                         Select rec

            Return query.ToList
        End Using
    End Function
    Public Shared Function Create(ByVal zObject As CHOFERES) As Boolean
        Try
            Using bd As New gas_gasdesuvecinoEntities
                bd.CHOFERES.Add(zObject)
                bd.SaveChanges()
                Return True
            End Using
        Catch ex As Exception
            Return False
        End Try
    End Function
    Public Shared Function Update(ByVal zObject As CHOFERES) As CHOFERES
        Try
            Using bd As New gas_gasdesuvecinoEntities
                Dim query = (From rec In bd.CHOFERES
                              Where rec.RUT = zObject.RUT
                              Select rec).Single

                query.NOMBRES = zObject.NOMBRES
                query.APELLIDOPATERNO = zObject.APELLIDOPATERNO
                query.APELLIDOMATERNO = zObject.APELLIDOMATERNO
                query.FECHANACIMIENTO = zObject.FECHANACIMIENTO
                query.DIRECCION = zObject.DIRECCION
                query.FONO = zObject.FONO
                query.AFP = zObject.AFP
                query.ACTIVO = True
                bd.SaveChanges()
                Return query
            End Using
        Catch ex As Exception
            Return Nothing
        End Try
    End Function
    Public Shared Function Delete(ByVal zId As String) As Boolean
        Try
            Using bd As New gas_gasdesuvecinoEntities
                Dim del = (From rec In bd.CHOFERES
                          Where rec.RUT = zId
                          Select rec).Single

                del.ACTIVO = False
                bd.SaveChanges()
                Return True
            End Using
        Catch ex As Exception
            Return False
        End Try
    End Function
    Public Shared Function Exist(ByVal zId As String) As Boolean
        Try
            Using bd As New gas_gasdesuvecinoEntities
                Dim query = (From rec In bd.CHOFERES
                            Where rec.RUT = zId
                            Select rec).Count
                If query > 0 Then
                    Return True
                Else
                    Return False
                End If
            End Using
        Catch ex As Exception
            Return False
        End Try
    End Function

    Public Shared Function SearchByRut(ByVal zRut As String) As CHOFERES
        Try
            Using bd As New gas_gasdesuvecinoEntities
                Dim query = (From rec In bd.CHOFERES
                            Where rec.RUT = zRut And rec.ACTIVO
                            Select rec).Single
                Return query
            End Using
        Catch ex As Exception
            Return Nothing
        End Try
    End Function

End Class
